<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <%@ include file="/WEB-INF/view/jQgrid.jsp"%>
    <link rel="stylesheet" href='<%=contextPath %>/assets/jquery.jOrgChart.css'/>
    <script type='text/javascript' src='<%=contextPath %>/assets/js/jquery-2.0.3.min.js'></script>
    <script type='text/javascript' src='<%=contextPath %>/assets/jquery.jOrgChart.js'></script>
    <style>
        a {
            text-decoration: none;
            color: #fff;
            font-size: 12px;
        }
        .jOrgChart .node {
            width: 120px;
            height: 50px;
            line-height: 50px;
            border-radius: 4px;
            margin: 0 8px;
        }
    </style>
</head>
<body style="background-color: white;" class="gray-bg">
<div class="container">
    <div class="row" >
    <div class="col-xs-6 col-sm-3">
	<input type="hidden" id="companyId" value="${companyId }" />
	<div id='jOrgChart' style="margin-top: 20px;"></div>
	</div>
	</div>
</div>
<script type='text/javascript'>
    $(function(){
    	var companyid = $("#companyId").val();
        //数据返回
        $.ajax({
        	url: '<%=contextPath%>/organize/getByCompanyId',
            type: 'GET',
            dataType: 'JSON',
            data: {companyId:companyid,action: 'org_select'},
            success: function(result){
                var showlist = $("<ul id='org' style='display:none'></ul>");
                showall(result, showlist);
                $("#jOrgChart").append(showlist);
                $("#org").jOrgChart( {
                    chartElement : '#jOrgChart',//指定在某个dom生成jorgchart
                    dragAndDrop : false //设置是否可拖动
                });

            }
        });
    });

    function showall(menu_list, parent) {
        $.each(menu_list, function(index, val) {
            if(val.childrens.length > 0){

                var li = $("<li></li>");
                li.append("<a>"+val.name+"</a>").append("<ul></ul>").appendTo(parent);
                //递归显示
                showall(val.childrens, $(li).children().eq(1));
            }else{
                $("<li></li>").append("<a>"+val.name+"</a>").appendTo(parent);
            }
        });

    }
    function getOrgId(val) {
    }

</script>
</body>
</html>